﻿using UnityEngine;
using System.Collections;




public class ViewFood : View
{

    public override void Update()
    {
        if (model.isAlive)
        {
            _transform.position = new Vector3(model.x, model.y, _transform.position.z);

            this._render.enabled = model.visible;
        }
        else
        {
            this.Dispose();
        }
    }

    public override bool Init()
    {
        base.Init();
        this._obj = PrefabsMgr.Load(DATA.PREFABS_FILE_FOOD);

        this._transform = _obj.GetComponent<Transform>();

        this.model = this._model as Food;

        this._render = _obj.GetComponent<SpriteRenderer>();
        this._render.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));

 
            this._obj.transform.localScale = new Vector3(model.scale, model.scale, 1.0f);
      


        return true;
    }

    public override void OnEvent(string type, object userData)
    {

    }
    public override void OnExit()
    {
        ViewMgr.ins.Remove(this);
        PrefabsMgr.Destroy(this._obj);

        base.OnExit();
    }



    private Food model = null;
    private Transform _transform = null;
    private GameObject _obj = null;
    private SpriteRenderer _render = null;

}


